package com.study.strategy.v2;

public class StrategyTestV2 {
    public static void main(String[] args) {
        Zombie zombie = new NormalZombie();
        zombie.display();
        zombie.move();
        zombie.attack();

        Zombie zombie2 = new FlogZombie();
        zombie2.display();
        zombie2.move();
        zombie2.attack();

        //公共的属性进行抽取 然后对策略进行抽象,让具体去实现 以后当需要用新的策略时我们只需要去新建策略然后进行组装即可 不会存在很多继承的关系 把类跟结构搞得很乱

        Zombie zombie3 = new FlogZombie();
        zombie3.setAttackAble(new hitAttack());
        zombie3.display();
        zombie3.move();
        zombie3.attack();



    }
}


//移动策略
interface MoveAble{
    void move();
}

//攻击策略
interface AttackAble{
    void attack();
}

abstract class Zombie{

    abstract public void display();

    MoveAble moveAble;
    AttackAble attackAble;

    public Zombie(MoveAble moveAble, AttackAble attackAble) {
        this.moveAble = moveAble;
        this.attackAble = attackAble;
    }

    abstract void move();
    abstract void attack();

    public MoveAble getMoveAble() {
        return moveAble;
    }

    public void setMoveAble(MoveAble moveAble) {
        this.moveAble = moveAble;
    }

    public AttackAble getAttackAble() {
        return attackAble;
    }

    public void setAttackAble(AttackAble attackAble) {
        this.attackAble = attackAble;
    }
}

//移动策略实现
class StepByStepMove implements MoveAble{

    @Override
    public void move() {
        System.out.println("一步一步走");
    }
}

//攻击策略实现
class BiteAttack implements AttackAble{

    @Override
    public void attack() {
        System.out.println("咬");
    }
}

//攻击策略实现
class hitAttack implements AttackAble{

    @Override
    public void attack() {
        System.out.println("打");
    }
}


//普通僵尸
class NormalZombie extends Zombie{

    public NormalZombie(){
        super(new StepByStepMove(),new BiteAttack());
    }

    public NormalZombie(MoveAble moveAble, AttackAble attackAble) {
        super(moveAble, attackAble);
    }

    @Override
    public void display() {
        System.out.println("我是普通僵尸");
    }

    @Override
    void move() {
        moveAble.move();
    }

    @Override
    void attack() {
        attackAble.attack();
    }
}


//旗手僵尸
class FlogZombie extends Zombie{

    public FlogZombie(){
        super(new StepByStepMove(),new BiteAttack());
    }

    public FlogZombie(MoveAble moveAble, AttackAble attackAble) {
        super(moveAble, attackAble);
    }

    @Override
    public void display() {
        System.out.println("我是旗手僵尸");
    }

    @Override
    void move() {
        moveAble.move();
    }

    @Override
    void attack() {
        attackAble.attack();
    }
}



